package com.yswy.backstage.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yswy.backstage.dto.req.PackageManageAddUpdateVo;
import com.yswy.backstage.dto.req.PackageManageListVo;
import com.yswy.backstage.service.PackageManageLogService;
import com.yswy.backstage.service.PackageManageService;
import com.yswy.domain.entity.PackageManage;
import com.yswy.domain.entity.user.User;
import com.yswy.domain.vo.gld.addOrUpate.PackageManageAddOrUpdate;
import com.yswy.domain.vo.gld.addOrUpate.base.BaseReqVO;
import com.yswy.domain.vo.gld.list.PackageManageLogList;
import com.yswy.domain.vo.gld.search.PackageManageIdSearch;
import com.yswy.domain.vo.gld.search.PackageManageSearch;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

import static com.yswy.backstage.utils.GldTokenUtils.getUser;

@RestController
@RequestMapping("/pack")
@ApiModel("渠道包")
@Api(tags = "渠道包")
public class PackageManageController {

    @Autowired
    private PackageManageService packageManageService;

    @Autowired
    private PackageManageLogService packageManageLogService;

    @PostMapping("/pagePackageManage")
    @ApiOperation(value = "渠道包列表")
    public Page<PackageManage> pagePackageManage(@RequestBody PackageManageSearch filter, HttpServletRequest request) {
        return packageManageService.pagePackageManage(filter );
    }

    @GetMapping("/listPackageManage")
    @ApiOperation(value = "渠道包列表")
    public List<PackageManage> listPackageManage(@RequestParam(value = "packageManageId" ,required = false) Long packageManageId,
                                                 HttpServletRequest request) {
        return packageManageService.listPackageManage(packageManageId);
    }

    @PostMapping("/addPackageManage")
    @ApiOperation(value = "添加渠道包")
    public void addPackageManage(@RequestBody @Validated(BaseReqVO.CREATE.class) PackageManageAddOrUpdate filter, HttpServletRequest request) {
        packageManageService.addOrUpdate(filter );
    }

    @PostMapping("/updatePackageManage")
    @ApiOperation(value = "修改渠道包")
    public void updatePackageManage(@RequestBody @Validated(BaseReqVO.UPDATE.class) PackageManageAddOrUpdate filter, HttpServletRequest request) {
        packageManageService.addOrUpdate(filter );
    }

    @GetMapping("/delPackageManage")
    @ApiOperation(value = "删除渠道包")
    public void delPackageManage(@RequestParam(value = "projectId") Long projectId, HttpServletRequest request) {
        packageManageService.delPackageManage(projectId);
    }

    @GetMapping("/isExistchannel")
    @ApiOperation(value = "渠道是否存在")
    public Boolean isExistchannel(@RequestParam(value = "packageManageId") Long packageManageId
            ,@RequestParam(value = "channel") String channel  ) {
        return packageManageService.isExistchannel(packageManageId ,channel);
    }


    @GetMapping("/addPackageManageLog")
    @ApiOperation(value = "打包")
    public void addPackageManageLog(@RequestParam(value = "packageManageLogId") Long packageManageLogId
            , HttpServletRequest request) {
        packageManageLogService.addPackageManageLog(packageManageLogId );
    }

    @PostMapping("/pagePackageManageLog")
    @ApiOperation(value = "打包记录列表")
    public Page<PackageManageLogList> pagePackageManageLog(@RequestBody PackageManageIdSearch req, HttpServletRequest request) {
        return packageManageLogService.pagePackageManageLog(req);
    }

    @GetMapping("/updateIsRenew")
    @ApiOperation(value = "提示更新")
    public void updateIsRenew(@RequestParam(value = "packageManageLogId") Long packageManageLogId,
                              @RequestParam(value = "isRenew") Integer isRenew
            , HttpServletRequest request) {
        packageManageLogService.updateIsRenew(packageManageLogId , isRenew );
    }
}



